# import socket
#
# g_open = b"\xA0\x01\x00\xA1"
# g_close = b"\xA0\x01\x01\xA2"
#
# y_open = b"\xA0\x02\x01\xA3"
# y_close = b"\xA0\x02\x00\xA2"
#
# r_open = b"\xA0\x03\x01\xA4"
# r_close = b"\xA0\x03\x00\xA3"
#
# s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# s1.settimeout(3)
# s1.connect(("192.168.2.196", 8080))
# s1.send(g_close)
# s1.close()

import socket
import time
from threading import Thread


class Client(Thread):

    def __init__(self, port):
        Thread.__init__(self)
        self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.client.settimeout(3)
        self.client.connect(('192.168.2.201', port))
        self.port = port

    def run(self):
        while True:
            msg = str(self.port) + ': from client'
            self.client.send(msg.encode('utf-8'))
            time.sleep(0.5)


for i in range(7):
    port = 9090 + i
    client = Client(port)
    client.start()

while True:
    i = 4

import cv2

cap = cv2.VideoCapture("rtsp://admin:hdu417417@192.168.2.3/Streaming/Channels/101")
i = 0
while True:
    _, frame = cap.read()
    cv2.imshow("123", frame)
    cv2.waitKey(1)
    i += 1
    if i == 50:
        cv2.imwrite("img.jpg", frame)
        break
